#ifndef WEBDOWNLOAD_H
#define WEBDOWNLOAD_H
#include<string>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <curl/curl.h>
#include <curl/easy.h>

class WebDownload
{
public:
    /*
     * GetInsyance()
     * get a single object
     * @return WebDownload
     */
    static WebDownload* GetInstance();

    /*
     * GoDownload(const std::string& url,const std::string& outfilename)
     * start download the html data
     * @Param url:the dest url
     * @Param outfilename:the html data of output file
     * @Param sync:appoint the download is sync or not sync
     * @return bool:if return true:success,else failed
     */
    bool GoDownload(const std::string& url,const std::string& outfilename);

    /*
     *WriteFunc(void* ptr,size_t size,size_t ncount,void* stream)
     * The write data into file of callback function
     * @Param ptr:received of data
     * @Param size:the size of per data
     * @Param ncount:the count of data
     * @Param stream:the output of file pointer
     * @return size_t:each data of size
     */
    static size_t WriteFunc(void* ptr,size_t size,size_t ncount,void* stream);

    /*
     * Release()
     * release the download instance
     */
    static void Release();
private:
    WebDownload();
    ~WebDownload();

    CURL* m_curl;
    static WebDownload* m_instance;
};

#endif // WEBDOWNLOAD_H
